using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace FBPChaos
{
	public class Spell
	{
		int damage;
		string lawOrChaos;
		int range;
		string spellDescription;
		int spellLevel;
		string spellName;
		string spellType;
		string spellSubType;
        Monster monsterAssociated;
        int chance; //the chance of the spell being generated

        public Spell(string line, List<Monster> availableMonsters)
        {
            //find semi colon
            //take string between semi colon and first character or semi colon and previous semi colon and assign to value; 
            int first = 0;
            int last;
            int numberOfAttributes = 10;
            string[] attribute;
            attribute = new string[numberOfAttributes];
            try
            {
                last = line.IndexOf(";");

                for (int counter = 0; counter < numberOfAttributes; counter++)
                {
                    attribute[counter] = line.Substring(first, last - first);
                    first = last + 1;
                    last = line.IndexOf(";", first);
                }
                damage = int.Parse(attribute[0]);
                lawOrChaos = attribute[1];
                range = int.Parse(attribute[2]);
                spellDescription = attribute[3];
                spellLevel = int.Parse(attribute[4]);
                spellName = attribute[5];
                spellType = attribute[6];
                spellSubType = attribute[7];
                monsterAssociated = findMonster(attribute[8], availableMonsters);
                chance = int.Parse(attribute[9]);
            }
            catch (Exception e)
            {

            }
        }

        private Monster findMonster(string name, List<Monster> availableMonsters)
        {
            int counter = 0;
            while (counter < availableMonsters.Count)
            {
                if (availableMonsters[counter].MonsterName == name)
                    return availableMonsters[counter];
                counter++;
            }
            return null;
        }
        
        public Monster summonMonster()
		{	
            return new Monster(monsterAssociated);
        }

        public string Name
        {
            get { return spellName; }
        }

        public int Chance
        {
            get { return chance; }
        }
	}
}
